api-monitoring-metrics
Documentation for api-monitoring-metrics
Overview
The api-monitoring-metrics
endpoint is part of the Flask application designed to monitor the availability of various internal and external APIs. The application collects metrics and exposes them in a format compatible with Prometheus.
Components
-
Flask Application:
- Endpoint:
/api-monitoring-metrics
- Function: Collects and returns API availability metrics.
- Endpoint:
-
Prometheus Client:
- Libraries Used:
prometheus_client
for creating and exposing metrics. - Metrics: Custom metrics for internal and external API availability.
- Libraries Used:
-
Environment Variables:
- API Endpoints: Defined in the environment variables, categorized as internal and external APIs.
-
Logging:
- Logging Setup: Uses Python's
logging
module to log information about API details and availability checks.
- Logging Setup: Uses Python's
-
Scheduler:
- Background Scheduler: Uses
apscheduler
to schedule background tasks.
- Background Scheduler: Uses
Key Functions
-
get_api_endpoints
:- Retrieves API endpoint details from environment variables.
- Categorizes endpoints into internal and external APIs.
-
parse_api_details
:- Parses the API details from environment variables into a dictionary format.
-
check_availability
:- Checks the availability of each API endpoint.
- Constructs Prometheus-compatible metrics based on the API response status.
-
api_monitoring_metrics
:- Flask route that calls
check_availability
and returns the metrics.
- Flask route that calls
Process Diagram
Here's the process flow of the monitoring setup:
Steps to Implement
- Set Up Environment Variables: Ensure all required environment variables are set, either in a
.env
file or directly in the deployment configuration. - Initialize the Flask Application: Deploy the Flask application using the specified configurations.
- Expose Metrics: The
/api-monitoring-metrics
endpoint exposes the collected metrics for Prometheus to scrape.
Steps to Deployment
Ensure all required environment variables are set.
environment: "prod"
This should be set as "dev"/"ts"/"sapw"/"prod" based on the deployment environment
api configurations
Format of the api:
api_internal_tenant_name_component: "component:component_name, microservice:microservice_name, endpoint:endpoint_link"
All the endpoints should be replaced by the endpoints from corresponding environmnet.
env variable name | endpoint |
---|---|
api_internal_aokplus_OGS | OGS API |
api_internal_aokplus_CRM | CRM api |
api_internal_aokplus_BonusPolicies | Bonus Policies API |
api_internal_aokplus_BonusMeasures | Bonus Measures api |
api_external_aokplus_Alemda | Alemda API |
api_external_aokplus_Docyet | Docyet api |
api_external_aokplus_Wonderpush | Wonderpush api |
api_external_aokplus_DoctorSearch | Doctor Search api |
api_external_aokplus_Mindshine | Mindshine api |
api_external_aokplus_Thryve | CRM Thryve |